﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;
using System.IO;
using Microsoft.Xna.Framework.Content;
using dahtd4ever.GameScreens;

namespace dahtd4ever.GameScreens
{
    public class Levelauswahl
    {
        public SpriteBatch sb;
        Game1 g;
        GameScreen gs;
        int level = 1;
        List<Text> menuItems;
        Text activeItem;
        Text t;

        public Levelauswahl(Game1 g, GameScreen gs) {
            this.g = g;
            this.gs = gs;
            menuItems = new List<Text>();


            for (int i = 0; i < gs.levelManager.getLevels().Count; i++)
            {
                String txt = gs.levelManager.getLevels()[i].getId().ToString()
                                + " - "
                                + gs.levelManager.getLevels()[i].getDescription();

                t = new Text(g, txt, new Vector2(0, 30 * i), true);
                menuItems.Add(t);
            }
        }

        public void Update(GameTime gameTime)
        {
            
            for (int i = 0; i < menuItems.Count; i++)
            {
                menuItems[i].update(gameTime);
            }

            if (ScreenManager.keyboard.MenuDown) {
                level++;
                if (level > menuItems.Count - 1)
                {
                    level = 0;
                }
            }

            if (ScreenManager.keyboard.MenuUp)
            {
                level--;
                if (level < 0) {
                    level = menuItems.Count - 1;
                }
            }



            activeItem = menuItems[level];

            foreach (Text tx in menuItems)
            {
                if (tx == activeItem)
                    tx.setBubble(true);
                else
                    tx.setBubble(false);
                tx.update(gameTime);
            }

            if (ScreenManager.keyboard.MenuSelect){
                gs.actualLevel = level + 1;
                gs.reset();
                ScreenManager.gameState = GameState.Play;
            }

        }

        public void Draw()
        {
            for (int i = 0; i < menuItems.Count; i++)
            {
                menuItems[i].draw();
            }

            g.spriteBatch.Begin();
            g.spriteBatch.End();
        }

    }

}

